<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="com.doone.telmarket.domain.ibator.ServiceTypeExample"%>
<%@page import="com.doone.telmarket.domain.ibator.ServiceType"%>
<%@page import="com.doone.telmarket.domain.Service"%>
<%@ taglib prefix="se" uri="/WEB-INF/serviceTypeTag.tld"%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>main</title>
<link rel="stylesheet" rev="stylesheet"
	href="${pageContext.request.contextPath}/css/admin/style-admin.css"
	type="text/css" media="all" />
<script type="text/javascript"
	src="${pageContext.request.contextPath}/ckeditor/ckeditor.js"></script>
<script src="${pageContext.request.contextPath}/js/jquery.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/js/jquery.ui.draggable.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/js/jquery.alerts.js" type="text/javascript"></script>
<link href="${pageContext.request.contextPath}/css/jquery.alerts.css" rel="stylesheet" type="text/css" media="screen" />
<style type="text/css">

.file{border:1px solid #333333;color:#666666;background:#eeeeee;font:normal 12px Tahoma;height:18px}
</style>
<script type="text/javascript">
	$(document).ready(function(){
		
		$("#fom").submit(function(){
			if($("#serviceId").val()==""){
					jAlert("请输入增值业务ID","消息");
					$("#serviceId").focus();
					return false;
			}else if(isNaN($("#serviceId").val())){
				jAlert("值业务的编码只能是数字","消息");
				$("#serviceId").focus();
				return false;
			}
			if($("#serviceName").val()==""){
				jAlert("请输入增值业务名称","消息");
				$("#serviceName").focus();
				return false;
			}
			if($("#serviceType").val()=="0"){
				jAlert("请选择增值业务服务类别","消息");
				$("#serviceType").focus();
				return false;
			}
			if($("#serviceClassify").val()=="0"){
				jAlert("请选择增值业务功能类别","消息");
				$("#serviceClassify").focus();
				return false;
			}
			if($("#value").val()==""){
				jAlert("请输入增值业务的价格","消息");
				$("#value").focus();
				return false;
			}else if(isNaN($("#value").val())){
				jAlert("值业务的价格只能是数字","消息");
				$("#value").focus();
				return false;
			}
			if($("#serviceDesc").val()==""){
				jAlert("请输入增值业务的简述","消息");
				$("#serviceDesc").focus();
				return false;
			}
			if($("#spname").val()==""){
				jAlert("请输入增值业务提供商","消息");
				$("#spname").focus();
				return false;
			}
			if($("#smallImage").val()==""){
				jAlert("请选择增值业务的缩略图","消息");
				$("#smallImage").focus();
				return false;
			}else{
				var name = $("#smallImage").val();
				name = name.substring(name.lastIndexOf("."));
				if(name!=".jpg"&&name!=".png"&&name!=".gif"){
					jAlert("增值业务的缩略图只能是JPG.PNG.GIF格式的缩略图","消息");
					$("#smallImage").focus();
					return false;
				}
			}
			if($("#bigImage").val()==""){
				jAlert("请选择增值业务的LOGO","消息");
				$("#bigImage").focus();
				return false;
			}else{
				var name = $("#bigImage").val();
				name = name.substring(name.lastIndexOf("."));
				if(name!=".jpg"&&name!=".png"&&name!=".gif"){
					jAlert("增值业务的LOGO只能是JPG.PNG.GIF格式的缩略图","消息");
					$("#bigImage").focus();
					return false;
				}
			}
			if($("#flash").val()==""){
				jAlert("请选择增值业务的体验FLASH","消息");
				$("#flash").focus();
				return false;
			}else{
				var name = $("#flash").val();
				name = name.substring(name.lastIndexOf("."));
				if(name!=".swf"){
					jAlert("增值业务的体验FLASH只能是SWF格式的FLASH","消息");
					$("#flash").focus();
					return false;
				}
			}
			if($("#grade").val()==""){
				jAlert("请选择增值业务的推荐星级","消息");
				$("#grade").focus();
				return false;
			}

			var Content =FCKeditorAPI.GetInstance("serviceContent").GetXHTML();
			if(Content == ""){
				jAlert("请输入增值业务的详细介绍","消息");
				return false;
			}
			return true;
		});

		
		CKEDITOR.replace('serviceContent');
		$("#query").click(function(){
			$("#serviceDiv").children().remove();
			$("#editor").css("display","none");
			$.ajax({
			    url: 'getServiceByType?serviceType='+$("#serviceType").val()+'&serviceClassify='+$("#serviceClassify").val(),
			    type: 'POST',
			    timeout: 5000,
			    error: function(){
			        jAlert('获取数据失败','消息');
			    },
			    success: function(msg){
			        if(msg!=""){
			        	eval('var obj='+msg);
			        	serviceList = obj;
			        	if(obj.length==0){
			        		var div1 = $('<div id=div1>  没有数据</div>');
			        		$("#serviceDiv").append(div1);
					    }else{
				        	for(var i=0;i<obj.length;i++){
					        	var div1 = $('<div></div>');
				        		
				        		div1.append("<div style='float:left;width:200px;'>"+obj[i].serviceName+"</div>");
				        		div1.append("<div style='float:left;width:50px; cursor: hand'><a onclick='modifyService("+obj[i].serviceCode
						        		+")'>编辑</a></div>");
				        		div1.append("<div style='float:left;width:50px; cursor: hand' id='"+obj[i].serviceCode+"'><a onclick='deleteById("+obj[i].serviceCode
						        		+")'>删除</a></div><br>");
				        		$("#serviceDiv").append(div1);
				        	}
			        	}
				    }
			    }
			});
			
		});
		});

	function modifyService(serviceId){
		$.ajax({
		    url: 'selectServiceById?serviceId='+serviceId,
		    type: 'POST',
		    timeout: 5000,
		    error: function(){
		        jAlert('请求服务错误','消息');
		    },
		    success: function(msg){
		        if(msg!=""){
		        	eval('var obj='+msg);
		        	$("#editor").css("display","");
		        	$("#serviceId").val(obj.serviceCode);
		        	$("#serviceName").val(obj.serviceName);
		        	$("#value").val(obj.serviceCost.money);
		        	$("#serviceDesc").val(obj.serviceSummary);
		        	$("#spname").val(obj.spName);
		        	
		        	$("#serviceType option[value='"+obj.serviceType.serviceTypeId+"']").attr("selected",true);
		        	$("#serviceClassify option[value='"+obj.serviceClassify.serviceClassifyId+"']").attr("selected",true)
		        	$("#serviceCodeType option[value='"+obj.serviceCodeType+"']").attr("selected",true)     	

				    }else{
				  jAlert('获取数据失败','消息');
				}
		    }
		});

		$.ajax({
		    url: 'selectServicePageByServiceId?serviceId='+serviceId,
		    type: 'POST',
		    timeout: 5000,
		    error: function(){
		        jAlert('获取数据失败','消息');
		    },
		    success: function(msg){
		        if(msg!=""){
		        	eval('var obj='+msg);
		        	//CKEDITOR.instances.editor1.setData(obj.serviceContent);
		        	//$("#serviceContent").val(obj.serviceContent);grade
		        	$("#grade  option[value='"+obj.recommandGrade+"']").attr("selected",true);
			    }
		    }
		});
	}

	function deleteById(serviceId){
		jConfirm('你确定删除吗?', '确认对话框', function(r) {
			if(r){
				$.ajax({
				    url: 'deleteById?serviceId='+serviceId,
				    type: 'POST',
				    timeout: 5000,
				    error: function(){
				        jAlert('请求服务错误','消息');
				    },
				    success: function(msg){
				        if(msg!="F"){
							jAlert("删除增值业务成功");
							$("#"+serviceId).parent().remove();	
							$("#editor").css("display","none");
					    }else{
							jAlert('删除增值业务成功','消息');
						}
				    }
				});
			}
		});
		
	}

	
   </script>
</head>
<body>
<table width="99%" border="0" cellpadding="0" cellspacing="0"
	class="CContent">
	<tr>
		<th class="tablestyle_title">增值业务管理</th>
	</tr>
	<tr>
		<td class="CPanel">
		<table border="0" cellpadding="0" cellspacing="0" style="width: 100%">
			<tr>
				<td align="left">&nbsp;&nbsp;&nbsp;<a href="service.jsp">新增增值业务</a>
				<a href="toOperationService.jsp">编辑增值业务</a></td>
			</tr>



			<tr align="center">
				<td class="TablePanel"></td>
			</tr>
			<tr>
				<TD width="100%">
				<fieldset style="height: 100%;"><legend>选择增值业务的服务类别及功能类别</legend>
				<form action="getServiceByType">功能类别:<se:showServiceClassify />服务类别:<se:showServiceType /><input
					type="button" id="query" value="查询" class="button" style="cursor: hand"></form>
				</fieldset>
				<fieldset style="height: 100%;"><legend>查询结果</legend>
				<div id="serviceDiv" style="width: 80%"></div>
				</fieldset>
				<form action="saveService?saveType=update" method="post"  enctype="multipart/form-data" id="fom">
				<fieldset style="height: 100%;display: none" id="editor" ><legend>编辑增值业务(带*的为必填)</legend>
				<table border="0" cellpadding="2" cellspacing="1"
					style="width: 100%">

					<tr>
						<td nowrap align="right" width="13%">增值业务代码：</td>
						<td width="32%">&nbsp;<input type="text" maxlength="30" 
							name="serviceId" id="serviceId" /><span style="color:black">*　 请输入数字类型的增值业务代码</span></td>
					</tr>
					<tr>
						<td nowrap align="right" width="13%">增值编码类别:</td>
						<td width="32%">&nbsp;<select name="serviceCodeType">
							<option value="P">产品类型</option>
							<option value="C">套餐类型</option>
						</select></td>
					</tr>
					<tr>
						<td nowrap align="right" width="13%">增值业务名称:</td>
						<td width="32%">&nbsp;<input type="text" maxlength="30" 
							name="serviceName" id="serviceName"><span style="color:black">*</span></td>
					</tr>
					<tr>
						<td nowrap align="right" width="13%">增值服务类别:</td>
						<td width="32%">&nbsp;<se:showServiceType/>
						</td>
					</tr>
					<tr>
						<td nowrap align="right" width="13%">增值功能类别:</td>
						<td width="32%">&nbsp;<se:showServiceClassify/></td>
					</tr>
					<tr>
						<td nowrap align="right" width="13%">增值业务价格:</td>
						<td width="32%">&nbsp;<input type="text" maxlength="4" size="4"
							name="value" id="value">元<span style="color:black">*　请输入整数类型的增值业务价格</span></td>
					</tr>
					<tr>
						<td nowrap align="right" width="13%">增值业务描述:</td>
						<td width="32%">&nbsp;<input type="text" maxlength="30" 
							name="serviceDesc" id="serviceDesc"><span style="color:black">*</span></td>
					</tr>
					<tr>
						<td nowrap align="right" width="13%">增值业务服务提供商:</td>
						<td width="32%">&nbsp;<input type="text" name="spName" id="spname"><span style="color:black">*</span></td>
					</tr>
				</table>
				<br />
				
				<table border="0" cellpadding="2" cellspacing="1"
					style="width: 100%">
					<tr>
						<td nowrap align="right" width="13%">增值业务缩略图:</td>
						<td width="32%">&nbsp;<input type="file" name="file" id="smallImage">
							<span style="color:black">*　 请选择后缀名为.jpg .gif .png格式的图片(尺寸为90*65)</span>
						</td>
					</tr>
					<tr>
						<td nowrap align="right" width="13%">增值业务LOGO:</td>
						<td width="32%">&nbsp;<input type="file" name="file" id="bigImage">
						<span style="color:black">*　 请选择后缀名为.jpg .gif .png格式的图片(尺寸为198*177)</span></td>
					</tr>
					<tr>
						<td nowrap align="right" width="13%">增值业务体验FLASH:</td>
						<td width="32%">&nbsp;<input type="file" name="file" id="flash">
						<span style="color:black">*　 请选择后缀名为.swf格式的FLASH</span></td>
					</tr>
					
					<tr>
						<td nowrap align="right" width="13%">增值业务推荐星级:</td>
						<td width="32%">&nbsp;<select name="serviceCodeGrade"  id="grade">
							<option value="1">&nbsp;1&nbsp;</option>
							<option value="2">&nbsp;2&nbsp;</option>
							<option value="3">&nbsp;3&nbsp;</option>
							<option value="4">&nbsp;4&nbsp;</option>
							<option value="5">&nbsp;5&nbsp;</option>
						</select>星</td>
					</tr>
        		<tr>
						<td nowrap align="right" width="13%">增值业务详细描述:</td>
						<td width="32%">
							<textarea rows="3" cols="5" name="serviceContent"></textarea>
						</td>
				</tr>
				<TR>
					<TD colspan="2" align="center" height="50px"><input type="submit"
						value="保存" class="button" /> <input type="button" name="Submit2"
						value="返回" class="button" onclick="window.history.go(-1);" /></TD>
				</TR>
				</table>
				</fieldset>
				</form>
				</TD>
			</TR>

		</TABLE>


		</td>
	</tr>
	<TR>
		<TD colspan="2" align="center" height="50px"></TD>
	</TR>
</TABLE>
</body>
</html>